package dataStructure.search;

import java.util.ArrayList;

/**
 * @author lhn
 * @date 2024-09-02 10:04
 */

public class InsertValueSearch {
    public static void main(String[] args) {
        int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
        12, 13, 14, 15, 15, 16};
        System.out.println("查找结果：");
        System.out.println(search(arr, 15, 0 , arr.length - 1));
    }

    public static int search(int[] arr, int target, int left, int right) {
        System.out.println("只查找一次");
        if (left > right || target < arr[left] || target > arr[right]) return -1;
        int mid = left + (right - left) * (target - arr[left]) / (arr[right] - arr[left]);
        System.out.println("mid:" + mid);
        if (arr[mid] == target) return mid;
        if (arr[mid] < target) return search(arr, target, mid + 1, right);
        else return search(arr, target, left, mid - 1);
    }

}
